package com.wandian.executor;

import com.wandian.util.Log;

/**
 * @author long
 * @Create 2012-11-13 下午3:08:54
 * @QQ 108232706
 * @version 1.0
 * @description Action
 */
public abstract class Action implements Runnable {
	private final ActionQueue queue;
	protected Long createTime;

	public Action(ActionQueue queue)
	{
		this.queue = queue;
		this.createTime = Long.valueOf(System.currentTimeMillis());
	}

	public ActionQueue getActionQueue() {
		return this.queue;
	}

	public void run()
	{
		if (this.queue != null) {
			long start = System.currentTimeMillis();
			try {
				execute();
				long end = System.currentTimeMillis();
				long interval = end - start;
				long lifeTime = end - this.createTime.longValue();
				if (interval > 1000L)
					Log.warn("execute atction " + toString() + " time : " + interval + ", lifeTime : " + lifeTime);
			} catch (Exception e) {
				Log.error("run action execute exception. action : " + toString(), e);
			} finally {
				this.queue.dequeue(this);
			}
		}
	}

	public abstract void execute();
}
